package com.example.administrator.pregnancyassistence.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.administrator.pregnancyassistence.R;

public class EatActivity extends AppCompatActivity {

    ListView list;
//    String[] notices={"五谷杂粮","蔬菜菌类","肉类/蛋类","水产/海鲜","水果","坚果类","零食小吃","饮品","豆/奶制品","加工食品","调味品","补品/草药"};
String[] notices={"一、孕期时的出行安全","二、孕妇的穿戴讲究","三、怀孕期间能使用什么药物","四、怀孕期间面部护理可以使用哪些","五、怀孕期间可以进行哪些体育运动"};
//    int[] icons = {R.drawable.eat1,R.drawable.eat2,R.drawable.eat3,R.drawable.eat4,R.drawable.eat11,R.drawable.eat12,R.drawable.eat13,R.drawable.eat14,R.drawable.eat21,R.drawable.eat22,R.drawable.eat23,R.drawable.eat24};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_eat);

        list = (ListView)findViewById(R.id.contact_list);
        list.setAdapter(new MyListViewAdapter());


        MyItemClickListener myItemClickListener = new MyItemClickListener();
        list.setOnItemClickListener(myItemClickListener);


    }


    public class MyItemClickListener implements AdapterView.OnItemClickListener{
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Intent intent = new Intent(EatActivity.this,ShowContentActivity.class);
            startActivity(intent);
        }
    }

    class MyListViewAdapter extends BaseAdapter {
//         Context context;
//         public MyListViewAdapter(Context context) {
//                        this.context = context;
//                     }
         @Override
         public int getCount() {
                       return notices.length;
                     }
         @Override
        public Object getItem(int position) {
                         return notices[position];
                     }
         @Override
         public long getItemId(int position) {
                         return position;
                     }
         @Override
         public View getView(int position, View convertView, ViewGroup parent) {
                         View view = View.inflate(EatActivity.this,R.layout.item_eat,null);
                         TextView textView = (TextView)view.findViewById(R.id.eat_tv);
//                         ImageView imageView = (ImageView) view.findViewById(R.id.eat_iv);
                         textView.setText(notices[position]);
//                         imageView.setImageResource(icons[position]);
                         return view;
                     }

     }
}
